#include <bits/stdc++.h>
using namespace std;
class Node{
public:
    int data;
    Node* next;
    Node(int d,Node* n = nullptr){
        data = d;
        next = n;
    }
};
Node* MeetingNode(Node* pHead)
{
    if(pHead == nullptr)
        return nullptr;
    Node* pSlow = pHead;
    Node* pFast;
    if(pSlow!= nullptr)
        pFast = pSlow->next;
    int pf_data = pFast->data;
    int ps_data = pSlow->data;
    while(pSlow!= nullptr && pFast!=nullptr)
    {
        if(pSlow == pFast)
            return pSlow;
        pSlow = pSlow->next;
        pFast = pFast->next;
        if(pFast != nullptr)
            pFast = pFast->next;
    }
    return nullptr;

}
int main() {
    Node* a = new Node(1);
    Node* b = new Node(2);
    Node* c = new Node(3);
    Node* d = new Node(4);
    Node* e = new Node(5);
    Node* f = new Node(6);
    a->next = b;
    b->next = c;
    c->next = d;
    d->next = e;
    e->next = d;
    Node* circle = MeetingNode(a);
    cout<<circle->data<<endl;
    delete a,b,c,d,e;

}